import React, { createContext, useReducer } from 'react';

const reducer = (state, action) => {
    switch (action.type) {
        case 'USER_INFO':
            return Object.assign(state, { userInfo: action.value });
        default:
            return state;
    }
};

export const GlobalContext = createContext(null);

export const GlobalProvide = ({ children }) => {
    const [state, dispatch] = useReducer(reducer, {
        userInfo: {}
    });
    return <GlobalContext.Provider value={{
        state,
        dispatch,
    }}>
        {children}
    </GlobalContext.Provider>
};